﻿using System;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Web.Services;
using Module;
using Module.QuanLyDuoc.HeThongNhapXuat;

namespace HospitalManager.Webservice.QuanLyDuoc.HeThongNhapXuat
{
    /// <summary>
    /// Summary description for wsPhieuXuatKhac
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
     [ScriptService]
    public class wsPhieuXuatKhac : WebService
    {
        private readonly PhieuXuatKhac _phieuXuatKhac = new PhieuXuatKhac();

        [WebMethod(EnableSession = true)]
        public string PhieuXuatKhac_Insert(string makho, string ngaygiao, string nguoigiao,
            string nguoinhan, string diengiai, string nguoitao)
        {
            var obj = new PhieuXuatKhac
            {
                MaKho = makho,
                NgayGiao = Convert.ToDateTime(DateTime.ParseExact(ngaygiao, "dd-MM-yyyy", null).ToString("yyyy-MM-dd")),
                NguoiGiao = nguoigiao,
                NguoiNhan = nguoinhan,
                DienGiai = diengiai,
                NguoiTao = nguoitao
            };
            return _phieuXuatKhac.PhieuXuatKhac_Insert(obj) ? obj.MaPhieu : string.Empty;
        }

        [WebMethod(EnableSession = true)]
        public bool PhieuXuatKhac_Update(string makho, string maphieu, string ngaygiao, string nguoigiao,
            string nguoinhan, string diengiai, string nguoitao)
        {
            var obj = new PhieuXuatKhac
            {
                MaKho = makho,
                MaPhieu = maphieu,
                NgayGiao = Convert.ToDateTime(DateTime.ParseExact(ngaygiao, "dd-MM-yyyy", null).ToString("yyyy-MM-dd")),
                NguoiGiao = nguoigiao,
                NguoiNhan = nguoinhan,
                DienGiai = diengiai,
                NguoiTao = nguoitao
            };
            return _phieuXuatKhac.PhieuXuatKhac_Update(obj);
        }

        [WebMethod(EnableSession = true)]
        public string PhieuXuatKhac_SelectById(string maphieu)
        {
            return JsonMethods.ToJsonString(_phieuXuatKhac.PhieuXuatKhac_SelectById(maphieu));
        }

        [WebMethod(EnableSession = true)]
        public bool PhieuXuatKhac_ChiTiet_Insert(string maphieu, string mavattu, int soluong, string nguoitao)
        {
            var obj = new PhieuXuatKhac
            {
                MaPhieu = maphieu,
                MaVatTu = mavattu,
                SoLuong = soluong,
                NguoiTao = nguoitao
            };
            return _phieuXuatKhac.PhieuXuatKhac_ChiTiet_Insert(obj);
        }
        
        [WebMethod(EnableSession = true)]
        public bool PhieuXuatKhac_ChiTiet_Deletee(string maphieu, string mavattu)
        {
            return _phieuXuatKhac.PhieuXuatKhac_ChiTiet_Delete(maphieu, mavattu);
        }
        
        [WebMethod(EnableSession = true)]
        public string PhieuXuatKhac_ChiTiet_SelectByMaPhieu(string maphieu)
        {
            return JsonMethods.ToJsonString(_phieuXuatKhac.PhieuXuatKhac_ChiTiet_SelectByMaPhieu(maphieu));
        }

        [WebMethod(EnableSession = true)]
        public string PhieuXuatKhac_ChiTiet_SelectByMaPhieu_ChiTiet(string maphieu)
        {
            return JsonMethods.ToJsonString(_phieuXuatKhac.PhieuXuatKhac_ChiTiet_SelectByMaPhieu_ChiTiet(maphieu));
        }

        [WebMethod(EnableSession = true)]
        public string PhieuXuatKhac_ChiTiet_SelectByMaPhieuMaVatTu(string maphieu, string mavattu)
        {
            return JsonMethods.ToJsonString(_phieuXuatKhac.PhieuXuatKhac_ChiTiet_SelectByMaPhieuMaVatTu(maphieu, mavattu));
        }
    }
}
